package com.ll.studentservice.controller;


import com.ll.commonUtils.R;
import com.ll.studentservice.entity.EduDepartment;
import com.ll.studentservice.entity.EduProfession;
import com.ll.studentservice.service.EduProfessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2020-11-26
 */
@Api(description = "专业增删改查API") //swagger界面提示
@RestController
@RequestMapping("/studentservice/eduprofession")
public class EduProfessionController {

    @Autowired
    private EduProfessionService eduProfessionService;

    @ApiOperation("添加专业信息")
    @PostMapping("addProfession")
    public R addDepartment(@RequestBody EduProfession eduProfession) {
        boolean save = eduProfessionService.save(eduProfession);

        //三元运算符
        return save ? R.ok() : R.error();
    }

    @ApiOperation("删除专业信息")
    @DeleteMapping("deleteProfession/{professionId}")
    public R deleteProfession(@PathVariable String professionId){
        boolean b = eduProfessionService.removeById(professionId);
        return b ? R.ok() : R.error();
    }

    @ApiOperation("查询所有专业信息")
    @GetMapping("findAllProperties")
    public R findAllProperties(){
        List<EduProfession> allPropertie = eduProfessionService.list(null);
        return R.ok().data("allProperties", allPropertie);
    }

    @ApiOperation("查询单个专业信息")
    @GetMapping("findOneProperties/{propertiesId}")
    public R findAllProperties(@PathVariable String propertiesId){
        EduProfession eduProfession = eduProfessionService.getById(propertiesId);
        if (StringUtils.isEmpty(eduProfession)){
            return R.error().message("没有这个专业");
        }else {
            return R.ok().data("item", eduProfession);
        }
    }

    @ApiOperation("修改专业信息")
    @PostMapping("uploadProperties")
    public R uploadProperties(@RequestBody EduProfession eduProfession){
        boolean b = eduProfessionService.updateById(eduProfession);
        return b ? R.ok() : R.error();
    }


}

